// pages/index/index.js
const request = require("../../utils/request1.js")
Page({
  data: {
    // 添加值
    goodsList:[],
    number: 0,
    borders: [],
    list:[
      {id:1,text:'首期月付',price:"￥155"},
      {id:2,text:'押金',price:"￥155"},
      {id:3,text:'共计',price:"￥155",color:'#b99946'},
      {id:4,text:'备注',price:"这是备注"}
    ]
  },
  onLoad: function () {
    // 线
    this.createBorders();
    // 提交订单
  // this.addOrderSubmission()
  },
  // 提交订单
    addOrderSubmission(){
    // 下单详情
      // wx.navigateTo({
      //   url: "/pages/OrderDetails/OrderDetails" 
      // });
      const _this = this
      request.wxRequest('order/add', function (err, data) {
      console.log(data);
      if (err) {
             // 失败；
      } else {
        
          _this.setData({
            goodsList: [..._this.data.goodsList, data] // 将新添加的商品添加到数组中
          })
      }
      }, 'POST', {
        goods_id:1,
        address_id:291,
        spec_id:9,
        dp:100,
        num:666,
        pay_type:2,
        remarks:''
      })
  },

  // 跳转详情页
  goDetails(){
    wx.navigateTo({
      url: "/pages/details/details" 
    });
  },
    increaseNumber() {
      this.setData({
        number: this.data.number + 1,
      });
    },
  
    decreaseNumber() {
      if (this.data.number > 0) {
        this.setData({
          number: this.data.number - 1,
        });
      }
    },
  createBorders: function () {
    const borders = [];
    for (let i = 1; i <= 18; i++) {
      const border = {};
      if (i % 2 === 0) {
        border.color = '#d4ddfc';
      } else {
        border.color = '#fbced1';
      }
      borders.push(border);
    }
    this.setData({ borders });
  }
});
